package com.nuoniu.sibanyun.mapper.production;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.nuoniu.sibanyun.entity.production.VProductionPlanDetail;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.math.BigDecimal;
import java.util.List;

/**
 * <p>
 * 主生产计划明细 Mapper 接口
 * </p>
 *
 * @author 小啊刚
 * @since 2021-03-11
 */
@Mapper
public interface VProductionPlanDetailMapper extends BaseMapper<VProductionPlanDetail> {

    @Update("update ma_mps_detail set is_operation=1 where id=#{voucherId} ")
    void updateOperationStatus(Integer voucherId);

    @Select("select count(1) from ma_mps_detail where order_id=#{orderId} and is_operation=0")
    Integer getOperationCount(Integer orderId);

    @Select("select d.* from ma_mps_detail d left join ma_mps m on d.order_id=m.id where m.company_id=#{companyId} and m.voucher_state=1 and d.is_operation=0")
    List<VProductionPlanDetail> getList(Integer companyId);

    @Delete("delete from ma_mps_detail where order_id=#{orderId}")
    void removeByOrderId(Long orderId);

    @Update("update ma_mps_detail set released_quantity = (#{baseQuantity} + released_quantity) where id=#{sourceDetailId}")
    void updateReleasedQuantity(Integer sourceDetailId, BigDecimal baseQuantity);

    @Update("update ma_mps_detail set released_quantity = (released_quantity - #{baseQuantity}) where id=#{sourceDetailId}")
    void updateReleasedQuantityReduce(Integer sourceDetailId, BigDecimal baseQuantity);
}
